1
|
|
|
// ============================================================================= |
2
|
|
|
|
3
|
|
|
// Utilities JavaScript (jQuery) |
4
|
|
|
|
5
|
|
|
// ============================================================================= |
6
|
|
|
|
7
|
|
|
(function($) { |
8
|
|
|
|
9
|
|
|
// Add isValid() |
10
|
|
|
|
11
|
|
|
$.fn.isValid = function(){ |
12
|
|
|
return this[0].checkValidity() |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
$(document).ready(function() { |
16
|
|
|
|
17
|
|
|
// Accordion Handlers ================================================== |
18
|
|
|
|
19
|
|
|
function accordionTrigger(trigger) { |
20
|
|
|
if ($(trigger).parent(".accordion").hasClass("active")) { |
21
|
|
|
$(trigger).attr("aria-expanded", "false"); |
22
|
|
|
$(trigger).parent(".accordion").removeClass("active"); |
23
|
|
|
$(trigger).parent(".accordion").find(".accordion-content").attr("aria-hidden", "true"); |
24
|
|
|
} |
25
|
|
|
else { |
26
|
|
|
$(trigger).attr("aria-expanded", "true"); |
27
|
|
|
$(trigger).parent(".accordion").addClass("active"); |
28
|
|
|
$(trigger).parent(".accordion").find(".accordion-content").attr("aria-hidden", "false"); |
29
|
|
|
} |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
$(document).on("click", ".accordion-trigger", function(e){ |
|
|
|
|
33
|
|
|
|
34
|
|
|
accordionTrigger(this); |
35
|
|
|
|
36
|
|
|
}); |
37
|
|
|
|
38
|
|
|
$(document).on("keyup", ".accordion-trigger", function(e){ |
39
|
|
|
|
40
|
|
|
if(e.which == 13) { |
41
|
|
|
accordionTrigger(this); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
}); |
45
|
|
|
|
46
|
|
|
// Modal Handlers ====================================================== |
47
|
|
|
|
48
|
|
|
function openModal(trigger) { |
49
|
|
|
|
50
|
|
|
var modalID = $(trigger).attr("data-modal-id"); |
51
|
|
|
var modal = $(".modal[data-modal-id="+modalID+"]"); |
52
|
|
|
var modalObject = $(trigger).parents(".modal-target-object"); |
53
|
|
|
$(".modal-overlay").addClass("active"); |
54
|
|
|
modal.addClass("active"); |
55
|
|
|
$("body").css("overflow", "hidden"); |
56
|
|
|
|
57
|
|
|
// Tab Items |
58
|
|
|
|
59
|
|
|
var focusableItems = modal.find(":focusable"); |
60
|
|
|
|
61
|
|
|
var firstInput = focusableItems.first(); |
62
|
|
|
var lastInput = focusableItems.last(); |
63
|
|
|
|
64
|
|
|
if (modal.find("form").length == 0) { |
|
|
|
|
65
|
|
|
lastInput.focus(); |
66
|
|
|
} |
67
|
|
|
else { |
68
|
|
|
firstInput.focus(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
modalTabHandler(firstInput, lastInput); |
72
|
|
|
modalDeleteTrigger(trigger, modal, modalObject); |
73
|
|
|
escapeModalHandler(); |
74
|
|
|
|
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$(document).on("click", ".modal-trigger", function(e){ |
|
|
|
|
78
|
|
|
|
79
|
|
|
openModal(this); |
80
|
|
|
|
81
|
|
|
}); |
82
|
|
|
|
83
|
|
|
$(document).on("keyup", ".modal-trigger", function(e){ |
84
|
|
|
|
85
|
|
|
if(e.which == 13) { |
86
|
|
|
openModal(this); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
}); |
90
|
|
|
|
91
|
|
|
|
92
|
|
|
function closeModal(trigger) { |
|
|
|
|
93
|
|
|
|
94
|
|
|
$(".modal-overlay").removeClass("active"); |
95
|
|
|
$(".modal").removeClass("active"); |
96
|
|
|
$("body").css("overflow", "visible"); |
97
|
|
|
|
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
$(document).on("click", ".modal-cancel-trigger", function(e){ |
|
|
|
|
101
|
|
|
|
102
|
|
|
closeModal(this); |
103
|
|
|
|
104
|
|
|
}); |
105
|
|
|
|
106
|
|
|
$(document).on("keyup", ".modal-cancel-trigger", function(e){ |
107
|
|
|
|
108
|
|
|
if(e.which == 13) { |
109
|
|
|
closeModal(this); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
}); |
113
|
|
|
|
114
|
|
|
// Delete Trigger ================================================== |
115
|
|
|
|
116
|
|
|
function modalDeleteTrigger(trigger, modal, object) { |
117
|
|
|
|
118
|
|
|
$(document).on("click", ".modal-delete-trigger", function(e){ |
|
|
|
|
119
|
|
|
|
120
|
|
|
closeModal(trigger); |
121
|
|
|
|
122
|
|
|
$(object).remove(); |
123
|
|
|
|
124
|
|
|
}); |
125
|
|
|
|
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
// Tab Handler ===================================================== |
129
|
|
|
|
130
|
|
|
function modalTabHandler(first, last) { |
131
|
|
|
|
132
|
|
|
$(document).on("keydown", function(e){ |
133
|
|
|
|
134
|
|
|
var keyCode = e.keyCode || e.which; |
135
|
|
|
|
136
|
|
|
if (keyCode == 9 && !e.shiftKey) { |
137
|
|
|
|
138
|
|
|
if ($(last).is(":focus")) { |
139
|
|
|
e.preventDefault(); |
140
|
|
|
$(first).focus(); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
} |
144
|
|
|
else if (keyCode == 9 && e.shiftKey) { |
145
|
|
|
|
146
|
|
|
if($(first).is(":focus")) { |
147
|
|
|
e.preventDefault(); |
148
|
|
|
$(last).focus(); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
}); |
154
|
|
|
|
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
// Escape Handler ================================================== |
158
|
|
|
|
159
|
|
|
function escapeModalHandler() { |
160
|
|
|
|
161
|
|
|
$(document).on("keyup", function(e){ |
162
|
|
|
|
163
|
|
|
if((e.key==='Escape'||e.key==='Esc'||e.keyCode===27)){ |
164
|
|
|
|
165
|
|
|
$(".modal-overlay").removeClass("active"); |
166
|
|
|
$(".modal").removeClass("active"); |
167
|
|
|
$("body").css("overflow", "visible"); |
168
|
|
|
|
169
|
|
|
// FF and compatible |
170
|
|
|
if (e.stopPropagation) { |
171
|
|
|
e.stopPropagation(); |
172
|
|
|
e.preventDefault(); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
}); |
178
|
|
|
|
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
// Form Handlers ======================================================= |
182
|
|
|
|
183
|
|
|
// Required Fields |
184
|
|
|
|
185
|
|
|
function requiredFields() { |
186
|
|
|
$("input:required, textarea:required").each(function(e) { |
|
|
|
|
187
|
|
|
$(this).parent().addClass("required"); |
188
|
|
|
$(this).parent().find("label").append("<span class='form__required'><i class='fa fa-asterisk' aria-label='Asterisk'></i></span>"); |
189
|
|
|
}); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
requiredFields(); |
193
|
|
|
|
194
|
|
|
// Label Handers =================================================== |
195
|
|
|
|
196
|
|
|
function labelHandlers() { |
197
|
|
|
|
198
|
|
|
$("[class*='form__input-wrapper'] input, [class*='form__input-wrapper'] textarea").focusin(function(e) { |
|
|
|
|
199
|
|
|
$(this).parent().addClass("active"); |
200
|
|
|
}); |
201
|
|
|
|
202
|
|
|
$("[class*='form__input-wrapper'] input, [class*='form__input-wrapper'] textarea").focusout(function(e) { |
|
|
|
|
203
|
|
|
|
204
|
|
|
// Check for existing value. |
205
|
|
|
|
206
|
|
|
if ($(this).val() == "") { |
207
|
|
|
$(this).parent().removeClass("active"); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
// Check Validity |
211
|
|
|
|
212
|
|
|
if ($(this).isValid() == true) { |
|
|
|
|
213
|
|
|
|
214
|
|
|
if ($(this).val() == "" || $(this).attr("type") == "password") { |
215
|
|
|
$(this).parent().removeClass("valid"); |
216
|
|
|
$(this).parent().removeClass("invalid"); |
|
|
|
|
217
|
|
|
} |
218
|
|
|
else { |
219
|
|
|
$(this).parent().addClass("valid"); |
220
|
|
|
$(this).parent().removeClass("invalid"); |
|
|
|
|
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
} |
224
|
|
|
else { |
225
|
|
|
|
226
|
|
|
if ($(this).attr("type") == "password") { |
227
|
|
|
return false; |
228
|
|
|
} |
229
|
|
|
else { |
|
|
|
|
230
|
|
|
$(this).parent().addClass("invalid"); |
231
|
|
|
$(this).parent().removeClass("valid"); |
|
|
|
|
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
}); |
237
|
|
|
|
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
labelHandlers(); |
241
|
|
|
|
242
|
|
|
//Individualize template attributes |
243
|
|
|
function appendToAttributes(parent, attribute, suffix, conditions = null) { |
244
|
|
|
var selector = "*[" + attribute + "]"; |
245
|
|
|
|
246
|
|
|
//If conditions is set, only modify attributes that also |
247
|
|
|
//satisfy that selector |
248
|
|
|
if (conditions) { |
249
|
|
|
selector = conditions + selector; |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
parent.find(selector).each(function() { |
253
|
|
|
$(this).attr(attribute, $(this).attr(attribute) + suffix); |
254
|
|
|
}); |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
//Individualize template attributes |
258
|
|
|
function replaceInAttributes(parent, attribute, oldString, newString, conditions = null) { |
259
|
|
|
var selector = "*[" + attribute + "]"; |
260
|
|
|
|
261
|
|
|
//If conditions is set, only modify attributes that also |
262
|
|
|
//satisfy that selector |
263
|
|
|
if (conditions) { |
264
|
|
|
selector = conditions + selector; |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
parent.find(selector).each(function() { |
268
|
|
|
$(this).attr(attribute, $(this).attr(attribute).replace(oldString, newString)); |
269
|
|
|
}); |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
//Return the next unused idAttr value |
273
|
|
|
function getNextItemId(parent, idAttr = "data-item-id") { |
274
|
|
|
var maxId = 0; |
275
|
|
|
parent.find("*[" + idAttr + "]").each(function() { |
276
|
|
|
var id = parseInt( $(this).attr(idAttr) ); |
277
|
|
|
if (id > maxId) { |
278
|
|
|
maxId = id; |
279
|
|
|
} |
280
|
|
|
}); |
281
|
|
|
return maxId + 1; |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
// Profile List Handlers =============================================== |
285
|
|
|
|
286
|
|
|
// Add Profile Element |
287
|
|
|
function addProfileElement(trigger) { |
288
|
|
|
|
289
|
|
|
// Get Parent |
290
|
|
|
var parent = $(trigger).parents(".profile-list"); |
291
|
|
|
|
292
|
|
|
// Get List Wrapper |
293
|
|
|
var wrapper = parent.find(".profile-element-list"); |
294
|
|
|
|
295
|
|
|
// Set Null to Hidden |
296
|
|
|
parent.find(".profile-null").removeClass("active"); |
297
|
|
|
|
298
|
|
|
// Get Template |
299
|
|
|
var template = parent.find(".profile-element.template").clone(); |
300
|
|
|
|
301
|
|
|
// Remove Template Class |
302
|
|
|
template.removeClass("template"); |
303
|
|
|
|
304
|
|
|
// Get New ID |
305
|
|
|
var newId = getNextItemId(wrapper); |
306
|
|
|
|
307
|
|
|
template.attr('data-item-id', newId); |
308
|
|
|
|
309
|
|
|
// Individualize Form IDs and labels |
310
|
|
|
appendToAttributes(template, 'id', '_' + newId); |
311
|
|
|
appendToAttributes(template, 'for', '_' + newId); |
312
|
|
|
|
313
|
|
|
// Individualize form names, except for submit buttons |
314
|
|
|
appendToAttributes(template, 'name', '[' + newId + ']', ':not([name=submit])'); |
315
|
|
|
// Individualize values on submit buttons |
316
|
|
|
appendToAttributes(template, 'value', '[' + newId + ']', '[name=submit]'); |
317
|
|
|
|
318
|
|
|
// Prepend Clone to the Wrapper |
319
|
|
|
wrapper.prepend(template); |
320
|
|
|
|
321
|
|
|
// Reactivate Required Fields |
322
|
|
|
requiredFields(); |
323
|
|
|
|
324
|
|
|
// Reactivate Labels |
325
|
|
|
labelHandlers(); |
326
|
|
|
|
327
|
|
|
// Reactivate Nested Relatives |
328
|
|
|
loadProfileRelatives(); |
329
|
|
|
|
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
// Click Trigger |
333
|
|
|
$(".profile-list__add-element-trigger").on("click", function(e) { |
334
|
|
|
|
335
|
|
|
// Prevent Default Functions |
336
|
|
|
e.preventDefault(); |
337
|
|
|
|
338
|
|
|
// Add Profile Elements |
339
|
|
|
addProfileElement(this); |
340
|
|
|
|
341
|
|
|
}); |
342
|
|
|
|
343
|
|
|
// Enter Key Trigger |
344
|
|
|
$(".profile-list__add-element-trigger").on("keyup", function(e) { |
345
|
|
|
|
346
|
|
|
if(e.which == 13) { |
347
|
|
|
|
348
|
|
|
// Prevent Default Functions |
349
|
|
|
e.preventDefault(); |
350
|
|
|
|
351
|
|
|
// Add Profile Elements |
352
|
|
|
addProfileElement(this); |
353
|
|
|
|
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
}); |
357
|
|
|
|
358
|
|
|
// Remove Profile Element |
359
|
|
|
|
360
|
|
|
// Add Profile Relative |
361
|
|
|
function addProfileRelative(trigger) { |
362
|
|
|
|
363
|
|
|
// Get Parent |
364
|
|
|
var parent = $(trigger).parents(".profile-relative-list"); |
365
|
|
|
|
366
|
|
|
// Get List Wrapper |
367
|
|
|
var wrapper = parent.find(".profile-relative-list__wrapper"); |
368
|
|
|
|
369
|
|
|
// Set Null to Hidden |
370
|
|
|
// parent.find(".profile-null").removeClass("active"); |
371
|
|
|
|
372
|
|
|
// Get Template |
373
|
|
|
var template = parent.find(".profile-relative.template").clone(); |
374
|
|
|
|
375
|
|
|
// Remove Template Class |
376
|
|
|
template.removeClass("template"); |
377
|
|
|
|
378
|
|
|
// Edit Form IDs |
379
|
|
|
|
380
|
|
|
// Tristan, help! x_x |
381
|
|
|
|
382
|
|
|
// Append Clone to the Wrapper |
383
|
|
|
wrapper.append(template); |
384
|
|
|
|
385
|
|
|
// Reactivate Required Fields |
386
|
|
|
requiredFields(); |
387
|
|
|
|
388
|
|
|
// Reactivate Labels |
389
|
|
|
labelHandlers(); |
390
|
|
|
|
391
|
|
|
// Reactivate Nested Relatives |
392
|
|
|
loadProfileRelativeDeletion(); |
393
|
|
|
|
394
|
|
|
} |
395
|
|
|
|
396
|
|
|
// Load Function |
397
|
|
|
function loadProfileRelatives() { |
398
|
|
|
|
399
|
|
|
// Click Trigger |
400
|
|
|
$(".profile-relative__add-trigger").off("click"); |
401
|
|
|
|
402
|
|
|
$(".profile-relative__add-trigger").on("click", function(e) { |
403
|
|
|
|
404
|
|
|
// Prevent Default Functions |
405
|
|
|
e.preventDefault(); |
406
|
|
|
|
407
|
|
|
// Add Profile Relative |
408
|
|
|
addProfileRelative(this); |
409
|
|
|
|
410
|
|
|
}); |
411
|
|
|
|
412
|
|
|
// Enter Key Trigger |
413
|
|
|
$(".profile-relative__add-trigger").off("keyup"); |
414
|
|
|
|
415
|
|
|
$(".profile-relative__add-trigger").on("keyup", function(e) { |
416
|
|
|
|
417
|
|
|
if(e.which == 13) { |
418
|
|
|
|
419
|
|
|
// Prevent Default Functions |
420
|
|
|
e.preventDefault(); |
421
|
|
|
|
422
|
|
|
// Add Profile Relative |
423
|
|
|
addProfileRelative(this); |
424
|
|
|
|
425
|
|
|
} |
426
|
|
|
|
427
|
|
|
}); |
428
|
|
|
|
429
|
|
|
} |
430
|
|
|
|
431
|
|
|
loadProfileRelatives(); |
432
|
|
|
|
433
|
|
|
// Remove Profile Relative |
434
|
|
|
function deleteProfileRelative(trigger) { |
435
|
|
|
|
436
|
|
|
$(trigger).parents(".profile-relative").remove(); |
437
|
|
|
|
438
|
|
|
} |
439
|
|
|
|
440
|
|
|
// Load Function |
441
|
|
|
function loadProfileRelativeDeletion() { |
442
|
|
|
|
443
|
|
|
// Click Trigger |
444
|
|
|
$(".profile-relative__remove-trigger").on("click", function(e) { |
445
|
|
|
|
446
|
|
|
// Prevent Default Functions |
447
|
|
|
e.preventDefault(); |
448
|
|
|
|
449
|
|
|
// Delete Profile Relative |
450
|
|
|
deleteProfileRelative(this); |
451
|
|
|
|
452
|
|
|
}); |
453
|
|
|
|
454
|
|
|
// Enter Key Trigger |
455
|
|
|
$(".profile-relative__remove-trigger").on("keyup", function(e) { |
456
|
|
|
|
457
|
|
|
if(e.which == 13) { |
458
|
|
|
|
459
|
|
|
// Prevent Default Functions |
460
|
|
|
e.preventDefault(); |
461
|
|
|
|
462
|
|
|
// Delete Profile Relative |
463
|
|
|
deleteProfileRelative(this); |
464
|
|
|
|
465
|
|
|
} |
466
|
|
|
|
467
|
|
|
}); |
468
|
|
|
|
469
|
|
|
} |
470
|
|
|
|
471
|
|
|
loadProfileRelativeDeletion(); |
472
|
|
|
|
473
|
|
|
// Experience Handlers ================================================= |
474
|
|
|
|
475
|
|
|
// Degrees |
476
|
|
|
|
477
|
|
|
function addDegree(trigger) { |
|
|
|
|
478
|
|
|
|
479
|
|
|
// Get Wrapper |
480
|
|
|
var wrapper = $(".application-post__experience-wrapper"); |
481
|
|
|
|
482
|
|
|
// Get Template |
483
|
|
|
var template = $(".application-post__accordion--degree.template").clone(); |
484
|
|
|
|
485
|
|
|
// Get New ID |
486
|
|
|
var newID = parseInt(wrapper.find("[class*='application-post__accordion--']").last().attr("data-experience-id")) + 1; |
487
|
|
|
|
488
|
|
|
// Remove Template Class |
489
|
|
|
template.removeClass("template"); |
490
|
|
|
|
491
|
|
|
// Assign the New ID |
492
|
|
|
template.attr("data-experience-id", newID); |
493
|
|
|
|
494
|
|
|
// Edit Form IDs |
495
|
|
|
|
496
|
|
|
// Degree Type |
497
|
|
|
template.find("[data-form-id*='experience-degree']").find("label").attr("for", "degree" + newID); |
498
|
|
|
template.find("[data-form-id*='experience-degree']").find("select").attr("id", "degree" + newID); |
499
|
|
|
|
500
|
|
|
// Area of Study |
501
|
|
|
template.find("[data-form-id*='experience-aos']").find("label").attr("for", "areaOfStudy" + newID); |
502
|
|
|
template.find("[data-form-id*='experience-aos']").find("input").attr("id", "areaOfStudy" + newID); |
503
|
|
|
|
504
|
|
|
// Institution |
505
|
|
|
template.find("[data-form-id*='experience-institution']").find("label").attr("for", "institution" + newID); |
506
|
|
|
template.find("[data-form-id*='experience-institution']").find("input").attr("id", "institution" + newID); |
507
|
|
|
|
508
|
|
|
// Start Date |
509
|
|
|
template.find("[data-form-id*='experience-start-date']").find("label").attr("for", "startDate" + newID); |
510
|
|
|
template.find("[data-form-id*='experience-start-date']").find("input").attr("id", "startDate" + newID); |
511
|
|
|
|
512
|
|
|
// End Date |
513
|
|
|
template.find("[data-form-id*='experience-end-date']").find("label").attr("for", "endDate" + newID); |
514
|
|
|
template.find("[data-form-id*='experience-end-date']").find("input").attr("id", "endDate" + newID); |
515
|
|
|
|
516
|
|
|
// Append Clone to the Wrapper |
517
|
|
|
wrapper.append(template); |
518
|
|
|
|
519
|
|
|
requiredFields(); |
520
|
|
|
labelHandlers(); |
521
|
|
|
|
522
|
|
|
} |
523
|
|
|
|
524
|
|
|
$("#addDegreeButton").on("click", function(e) { |
525
|
|
|
|
526
|
|
|
e.preventDefault(); |
527
|
|
|
|
528
|
|
|
addDegree(this); |
529
|
|
|
|
530
|
|
|
}); |
531
|
|
|
|
532
|
|
|
$("#addDegreeButton").on("keyup", function(e) { |
533
|
|
|
|
534
|
|
|
if(e.which == 13) { |
535
|
|
|
e.preventDefault(); |
536
|
|
|
addDegree(this); |
537
|
|
|
} |
538
|
|
|
|
539
|
|
|
}); |
540
|
|
|
|
541
|
|
|
// Courses |
542
|
|
|
|
543
|
|
|
function addCourse(trigger) { |
|
|
|
|
544
|
|
|
|
545
|
|
|
// Get Wrapper |
546
|
|
|
var wrapper = $(".application-post__experience-wrapper"); |
547
|
|
|
|
548
|
|
|
// Get Template |
549
|
|
|
var template = $(".application-post__accordion--course.template").clone(); |
550
|
|
|
|
551
|
|
|
// Get New ID |
552
|
|
|
var newID = parseInt(wrapper.find("[class*='application-post__accordion--']").last().attr("data-experience-id")) + 1; |
553
|
|
|
|
554
|
|
|
// Remove Template Class |
555
|
|
|
template.removeClass("template"); |
556
|
|
|
|
557
|
|
|
// Assign the New ID |
558
|
|
|
template.attr("data-experience-id", newID); |
559
|
|
|
|
560
|
|
|
// Edit Form IDs |
561
|
|
|
|
562
|
|
|
// Course Name |
563
|
|
|
template.find("[data-form-id*='experience-course-name']").find("label").attr("for", "courseName" + newID); |
564
|
|
|
template.find("[data-form-id*='experience-course-name']").find("input").attr("id", "courseName" + newID); |
565
|
|
|
|
566
|
|
|
// Institution |
567
|
|
|
template.find("[data-form-id*='experience-institution']").find("label").attr("for", "institution" + newID); |
568
|
|
|
template.find("[data-form-id*='experience-institution']").find("input").attr("id", "institution" + newID); |
569
|
|
|
|
570
|
|
|
// Start Date |
571
|
|
|
template.find("[data-form-id*='experience-start-date']").find("label").attr("for", "startDate" + newID); |
572
|
|
|
template.find("[data-form-id*='experience-start-date']").find("input").attr("id", "startDate" + newID); |
573
|
|
|
|
574
|
|
|
// End Date |
575
|
|
|
template.find("[data-form-id*='experience-end-date']").find("label").attr("for", "endDate" + newID); |
576
|
|
|
template.find("[data-form-id*='experience-end-date']").find("input").attr("id", "endDate" + newID); |
577
|
|
|
|
578
|
|
|
// Append Clone to the Wrapper |
579
|
|
|
wrapper.append(template); |
580
|
|
|
|
581
|
|
|
requiredFields(); |
582
|
|
|
labelHandlers(); |
583
|
|
|
|
584
|
|
|
} |
585
|
|
|
|
586
|
|
|
$("#addCourseButton").on("click", function(e) { |
587
|
|
|
|
588
|
|
|
e.preventDefault(); |
589
|
|
|
|
590
|
|
|
addCourse(this); |
591
|
|
|
|
592
|
|
|
}); |
593
|
|
|
|
594
|
|
|
$("#addCourseButton").on("keyup", function(e) { |
595
|
|
|
|
596
|
|
|
if(e.which == 13) { |
597
|
|
|
e.preventDefault(); |
598
|
|
|
addCourse(this); |
599
|
|
|
} |
600
|
|
|
|
601
|
|
|
}); |
602
|
|
|
|
603
|
|
|
// Work |
604
|
|
|
|
605
|
|
|
function addWork(trigger) { |
|
|
|
|
606
|
|
|
|
607
|
|
|
// Get Wrapper |
608
|
|
|
var wrapper = $(".application-post__experience-wrapper"); |
609
|
|
|
|
610
|
|
|
// Get Template |
611
|
|
|
var template = $(".application-post__accordion--work.template").clone(); |
612
|
|
|
|
613
|
|
|
// Get New ID |
614
|
|
|
var newID = parseInt(wrapper.find("[class*='application-post__accordion--']").last().attr("data-experience-id")) + 1; |
615
|
|
|
|
616
|
|
|
// Remove Template Class |
617
|
|
|
template.removeClass("template"); |
618
|
|
|
|
619
|
|
|
// Assign the New ID |
620
|
|
|
template.attr("data-experience-id", newID); |
621
|
|
|
|
622
|
|
|
// Edit Form IDs |
623
|
|
|
|
624
|
|
|
// Role |
625
|
|
|
template.find("[data-form-id*='experience-course-name']").find("label").attr("for", "role" + newID); |
626
|
|
|
template.find("[data-form-id*='experience-course-name']").find("input").attr("id", "role" + newID); |
627
|
|
|
|
628
|
|
|
// Group / Company |
629
|
|
|
template.find("[data-form-id*='experience-institution']").find("label").attr("for", "group" + newID); |
630
|
|
|
template.find("[data-form-id*='experience-institution']").find("input").attr("id", "group" + newID); |
631
|
|
|
|
632
|
|
|
// Description |
633
|
|
|
template.find("[data-form-id*='experience-description']").find("label").attr("for", "description" + newID); |
634
|
|
|
template.find("[data-form-id*='experience-description']").find("input").attr("id", "description" + newID); |
635
|
|
|
|
636
|
|
|
// Start Date |
637
|
|
|
template.find("[data-form-id*='experience-start-date']").find("label").attr("for", "startDate" + newID); |
638
|
|
|
template.find("[data-form-id*='experience-start-date']").find("input").attr("id", "startDate" + newID); |
639
|
|
|
|
640
|
|
|
// End Date |
641
|
|
|
template.find("[data-form-id*='experience-end-date']").find("label").attr("for", "endDate" + newID); |
642
|
|
|
template.find("[data-form-id*='experience-end-date']").find("input").attr("id", "endDate" + newID); |
643
|
|
|
|
644
|
|
|
// Append Clone to the Wrapper |
645
|
|
|
wrapper.append(template); |
646
|
|
|
|
647
|
|
|
requiredFields(); |
648
|
|
|
labelHandlers(); |
649
|
|
|
|
650
|
|
|
} |
651
|
|
|
|
652
|
|
|
$("#addWorkButton").on("click", function(e) { |
653
|
|
|
|
654
|
|
|
e.preventDefault(); |
655
|
|
|
|
656
|
|
|
addWork(this); |
657
|
|
|
|
658
|
|
|
}); |
659
|
|
|
|
660
|
|
|
$("#addWorkButton").on("keyup", function(e) { |
661
|
|
|
|
662
|
|
|
if(e.which == 13) { |
663
|
|
|
e.preventDefault(); |
664
|
|
|
addWork(this); |
665
|
|
|
} |
666
|
|
|
|
667
|
|
|
}); |
668
|
|
|
|
669
|
|
|
// Create Job Handlers ================================================= |
670
|
|
|
|
671
|
|
|
// Tasks |
672
|
|
|
|
673
|
|
|
function addTask(trigger) { |
|
|
|
|
674
|
|
|
|
675
|
|
|
// Get Wrapper |
676
|
|
|
var wrapper = $(".manager-jobs__create-task-wrapper"); |
677
|
|
|
|
678
|
|
|
// Get Template |
679
|
|
|
var template = $(".manager-jobs__create-task.template").clone(); |
680
|
|
|
|
681
|
|
|
console.log(wrapper.find(".manager-jobs__create-task")); |
|
|
|
|
682
|
|
|
|
683
|
|
|
// Get New ID |
684
|
|
|
if (wrapper.find(".manager-jobs__create-task").length == 0) { |
|
|
|
|
685
|
|
|
var newID = parseInt(template.attr("data-task-id")) + 1; |
686
|
|
|
} |
687
|
|
|
else { |
688
|
|
|
var newID = parseInt(wrapper.find("[class*='manager-jobs__create-task']").last().attr("data-task-id")) + 1; |
|
|
|
|
689
|
|
|
} |
690
|
|
|
|
691
|
|
|
// Remove Template Class |
692
|
|
|
template.removeClass("template"); |
693
|
|
|
|
694
|
|
|
// Assign the New ID |
695
|
|
|
template.attr("data-task-id", newID); |
696
|
|
|
|
697
|
|
|
// Add newID as suffix to all "id" and "for" attributes |
698
|
|
|
template.find("*[id]").each(function() { $(this).attr("id", this.id + newID)}); |
699
|
|
|
template.find("*[for]").each(function() { $(this).attr("for", $(this).attr("for") + newID)}); |
700
|
|
|
|
701
|
|
|
// Replace :id with newID in all form names |
702
|
|
|
template.find("*[name]").each(function() { $(this).attr('name', $(this).attr("name").replace(":id", newID))}); |
703
|
|
|
|
704
|
|
|
// Task (English) |
705
|
|
|
//template.find("[data-form-id*='task-english']").find("label").attr("for", "taskEN" + newID); |
706
|
|
|
//template.find("[data-form-id*='task-english']").find("input").attr("id", "taskEN" + newID); |
707
|
|
|
|
708
|
|
|
// Task (French) |
709
|
|
|
//template.find("[data-form-id*='task-french']").find("label").attr("for", "taskFR" + newID); |
710
|
|
|
//template.find("[data-form-id*='task-french']").find("input").attr("id", "taskFR" + newID); |
711
|
|
|
|
712
|
|
|
// Append Clone to the Wrapper |
713
|
|
|
wrapper.append(template); |
714
|
|
|
|
715
|
|
|
requiredFields(); |
716
|
|
|
labelHandlers(); |
717
|
|
|
deleteTaskTrigger(); |
718
|
|
|
|
719
|
|
|
} |
720
|
|
|
|
721
|
|
|
$("#addTaskButton").on("click", function(e) { |
722
|
|
|
|
723
|
|
|
e.preventDefault(); |
724
|
|
|
|
725
|
|
|
addTask(this); |
726
|
|
|
|
727
|
|
|
}); |
728
|
|
|
|
729
|
|
|
$("#addTaskButton").on("keyup", function(e) { |
730
|
|
|
|
731
|
|
|
if(e.which == 13) { |
732
|
|
|
e.preventDefault(); |
733
|
|
|
addTask(this); |
734
|
|
|
} |
735
|
|
|
|
736
|
|
|
}); |
737
|
|
|
|
738
|
|
|
// Task Deletion |
739
|
|
|
|
740
|
|
|
function deleteTask(trigger) { |
741
|
|
|
|
742
|
|
|
$(trigger).parents(".manager-jobs__create-task").remove(); |
743
|
|
|
|
744
|
|
|
} |
745
|
|
|
|
746
|
|
|
function deleteTaskTrigger() { |
747
|
|
|
|
748
|
|
|
$(".manager-jobs__delete-task-button").on("click", function(e) { |
749
|
|
|
|
750
|
|
|
e.preventDefault(); |
751
|
|
|
|
752
|
|
|
deleteTask(this); |
753
|
|
|
|
754
|
|
|
}); |
755
|
|
|
|
756
|
|
|
$(".manager-jobs__delete-task-button").on("keyup", function(e) { |
757
|
|
|
|
758
|
|
|
if(e.which == 13) { |
759
|
|
|
e.preventDefault(); |
760
|
|
|
deleteTask(this); |
761
|
|
|
} |
762
|
|
|
|
763
|
|
|
}); |
764
|
|
|
|
765
|
|
|
} |
766
|
|
|
|
767
|
|
|
deleteTaskTrigger(); |
768
|
|
|
|
769
|
|
|
// Skills |
770
|
|
|
|
771
|
|
|
function addSkill(trigger) { |
772
|
|
|
|
773
|
|
|
// Get Parent |
774
|
|
|
var parent = $(trigger).parents(".manager-jobs__skill-wrapper"); |
775
|
|
|
|
776
|
|
|
// Get Wrapper |
777
|
|
|
var wrapper = parent.find(".manager-jobs__create-skill-wrapper"); |
778
|
|
|
|
779
|
|
|
// Get Template |
780
|
|
|
var template = parent.find(".manager-jobs__create-skill.template").clone(); |
781
|
|
|
|
782
|
|
|
console.log(wrapper.find(".manager-jobs__create-skill")); |
|
|
|
|
783
|
|
|
|
784
|
|
|
// Remove Template Class |
785
|
|
|
template.removeClass("template"); |
786
|
|
|
|
787
|
|
|
// Get New ID |
788
|
|
|
var newId = getNextItemId(wrapper, "data-skill-id"); |
789
|
|
|
|
790
|
|
|
// Assign the New ID |
791
|
|
|
template.attr('data-skill-id', newId); |
792
|
|
|
|
793
|
|
|
// Individualize Form IDs and labels |
794
|
|
|
appendToAttributes(template, 'id', '_' + newId); |
795
|
|
|
appendToAttributes(template, 'for', '_' + newId); |
796
|
|
|
|
797
|
|
|
// Individualize form names, except for submit buttons |
798
|
|
|
appendToAttributes(template, 'name', '[' + newId + ']', ':not([name=submit])'); |
799
|
|
|
// Individualize values on submit buttons |
800
|
|
|
appendToAttributes(template, 'value', '[' + newId + ']', '[name=submit]'); |
801
|
|
|
|
802
|
|
|
//Differentiate real forms from templates |
803
|
|
|
replaceInAttributes(template, 'name', ':template', 'new'); |
804
|
|
|
|
805
|
|
|
// Append Clone to the Wrapper |
806
|
|
|
wrapper.append(template); |
807
|
|
|
|
808
|
|
|
requiredFields(); |
809
|
|
|
labelHandlers(); |
810
|
|
|
deleteSkillTrigger(); |
811
|
|
|
|
812
|
|
|
} |
813
|
|
|
|
814
|
|
|
$(".manager-jobs__add-skill-button").on("click", function(e) { |
815
|
|
|
|
816
|
|
|
e.preventDefault(); |
817
|
|
|
|
818
|
|
|
addSkill(this); |
819
|
|
|
|
820
|
|
|
}); |
821
|
|
|
|
822
|
|
|
$(".manager-jobs__add-skill-button").on("keyup", function(e) { |
823
|
|
|
|
824
|
|
|
if(e.which == 13) { |
825
|
|
|
e.preventDefault(); |
826
|
|
|
addSkill(this); |
827
|
|
|
} |
828
|
|
|
|
829
|
|
|
}); |
830
|
|
|
|
831
|
|
|
// Skill Deletion |
832
|
|
|
|
833
|
|
|
function deleteSkill(trigger) { |
834
|
|
|
|
835
|
|
|
$(trigger).parents(".manager-jobs__create-skill").remove(); |
836
|
|
|
|
837
|
|
|
} |
838
|
|
|
|
839
|
|
|
function deleteSkillTrigger() { |
840
|
|
|
|
841
|
|
|
$(".manager-jobs__delete-skill-button").on("click", function(e) { |
842
|
|
|
|
843
|
|
|
e.preventDefault(); |
844
|
|
|
|
845
|
|
|
deleteSkill(this); |
846
|
|
|
|
847
|
|
|
}); |
848
|
|
|
|
849
|
|
|
$(".manager-jobs__delete-skill-button").on("keyup", function(e) { |
850
|
|
|
|
851
|
|
|
if(e.which == 13) { |
852
|
|
|
e.preventDefault(); |
853
|
|
|
deleteSkill(this); |
854
|
|
|
} |
855
|
|
|
|
856
|
|
|
}); |
857
|
|
|
|
858
|
|
|
} |
859
|
|
|
|
860
|
|
|
deleteSkillTrigger(); |
861
|
|
|
|
862
|
|
|
// Questions |
863
|
|
|
|
864
|
|
|
function addQuestion(trigger) { |
|
|
|
|
865
|
|
|
|
866
|
|
|
// Get Wrapper |
867
|
|
|
var wrapper = $(".manager-jobs__create-question-wrapper"); |
868
|
|
|
|
869
|
|
|
// Get Template |
870
|
|
|
var template = $(".manager-jobs__create-question.template").clone(); |
871
|
|
|
|
872
|
|
|
console.log(wrapper.find(".manager-jobs__create-question")); |
|
|
|
|
873
|
|
|
|
874
|
|
|
// Get New ID |
875
|
|
|
if (wrapper.find(".manager-jobs__create-question").length == 0) { |
|
|
|
|
876
|
|
|
var newID = parseInt(template.attr("data-question-id")) + 1; |
877
|
|
|
} |
878
|
|
|
else { |
879
|
|
|
var newID = parseInt(wrapper.find("[class*='manager-jobs__create-question']").last().attr("data-question-id")) + 1; |
|
|
|
|
880
|
|
|
} |
881
|
|
|
|
882
|
|
|
// Remove Template Class |
883
|
|
|
template.removeClass("template"); |
884
|
|
|
|
885
|
|
|
// Assign the New ID |
886
|
|
|
template.attr("data-question-id", newID); |
887
|
|
|
|
888
|
|
|
// Add newID as suffix to all "id" and "for" attributes |
889
|
|
|
template.find("*[id]").each(function() { $(this).attr("id", this.id + newID)}); |
890
|
|
|
template.find("*[for]").each(function() { $(this).attr("for", $(this).attr("for") + newID)}); |
891
|
|
|
|
892
|
|
|
// Replace :id with newID in all form names |
893
|
|
|
template.find("*[name]").each(function() { $(this).attr('name', $(this).attr("name").replace(":id", newID))}); |
894
|
|
|
|
895
|
|
|
// Edit Form IDs |
896
|
|
|
// |
897
|
|
|
// // Queestion (English) |
898
|
|
|
// template.find("[data-form-id*='question-english']").find("label").attr("for", "questionEN" + newID); |
899
|
|
|
// template.find("[data-form-id*='question-english']").find("input").attr("id", "questionEN" + newID); |
900
|
|
|
// |
901
|
|
|
// // Queestion (French) |
902
|
|
|
// template.find("[data-form-id*='question-french']").find("label").attr("for", "questionFR" + newID); |
903
|
|
|
// template.find("[data-form-id*='question-french']").find("input").attr("id", "questionFR" + newID); |
904
|
|
|
|
905
|
|
|
// Append Clone to the Wrapper |
906
|
|
|
wrapper.append(template); |
907
|
|
|
|
908
|
|
|
requiredFields(); |
909
|
|
|
labelHandlers(); |
910
|
|
|
deleteQuestionTrigger(); |
911
|
|
|
|
912
|
|
|
} |
913
|
|
|
|
914
|
|
|
$("#addQuestionButton").on("click", function(e) { |
915
|
|
|
|
916
|
|
|
e.preventDefault(); |
917
|
|
|
|
918
|
|
|
addQuestion(this); |
919
|
|
|
|
920
|
|
|
}); |
921
|
|
|
|
922
|
|
|
$("#addQuestionButton").on("keyup", function(e) { |
923
|
|
|
|
924
|
|
|
if(e.which == 13) { |
925
|
|
|
e.preventDefault(); |
926
|
|
|
addQuestion(this); |
927
|
|
|
} |
928
|
|
|
|
929
|
|
|
}); |
930
|
|
|
|
931
|
|
|
// Question Deletion |
932
|
|
|
|
933
|
|
|
function deleteQuestion(trigger) { |
934
|
|
|
|
935
|
|
|
$(trigger).parents(".manager-jobs__create-question").remove(); |
936
|
|
|
|
937
|
|
|
} |
938
|
|
|
|
939
|
|
|
function deleteQuestionTrigger() { |
940
|
|
|
|
941
|
|
|
$(".manager-jobs__delete-question-button").on("click", function(e) { |
942
|
|
|
|
943
|
|
|
e.preventDefault(); |
944
|
|
|
|
945
|
|
|
deleteQuestion(this); |
946
|
|
|
|
947
|
|
|
}); |
948
|
|
|
|
949
|
|
|
$(".manager-jobs__delete-question-button").on("keyup", function(e) { |
950
|
|
|
|
951
|
|
|
if(e.which == 13) { |
952
|
|
|
e.preventDefault(); |
953
|
|
|
deleteQuestion(this); |
954
|
|
|
} |
955
|
|
|
|
956
|
|
|
}); |
957
|
|
|
|
958
|
|
|
} |
959
|
|
|
|
960
|
|
|
deleteQuestionTrigger(); |
961
|
|
|
|
962
|
|
|
}); |
963
|
|
|
|
964
|
|
|
})(jQuery); |
965
|
|
|
|
This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.